﻿using System;
using System.Web;
using System.Web.Mvc;

namespace Calico.Client.Filters
{
	/// <summary>
	/// Attribute to force cache expiration
	/// </summary>
	public class NoCache : ActionFilterAttribute
	{
		/// <summary>
		/// Returns nothing for now 
		/// </summary>
		/// <param name="filterContext"></param>
		public override void OnActionExecuted(ActionExecutedContext filterContext)
		{
			return;
		}

		/// <summary>
		/// Sets the response cache properties
		/// </summary>
		/// <param name="filterContext"></param>
		public override void OnActionExecuting(ActionExecutingContext filterContext)
		{
			// Set cache settings for no caching
			filterContext.HttpContext.Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1));
			filterContext.HttpContext.Response.Cache.SetValidUntilExpires(false);
			filterContext.HttpContext.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
			filterContext.HttpContext.Response.Cache.SetCacheability(HttpCacheability.NoCache);
			filterContext.HttpContext.Response.Cache.SetNoStore();
		}
	}
}